<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>根据区域设置格式化本地时间／日期</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.strftime" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strftime</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">strftime</span> &mdash; <span class="dc-title">根据区域设置格式化本地时间／日期</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.strftime-description">
  <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strftime</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timestamp</code><span class="initializer"> = time()</span></span>
  ] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   返回用给定的格式字串对给出的 <code class="parameter">timestamp</code>
   进行格式输出后的字符串。如果没有给出时间戳则用当前的本地时间。月份和星期几以及其它和语言有关的字符串写法和用
   <span class="function"><a href="setlocale.html" class="function">setlocale()</a></span> 设定的当前的区域有关。
  </p>
  <p class="para">
   可能不是所有的转换标记都被 C 库文件支持，这种情况下 PHP
   的 <span class="function"><strong>strftime()</strong></span>
   也不支持。此外，不是所有的平台都支持负的时间戳，因此日期的范围可能限定在不早于
   Unix 纪元。这意味着例如
   %e, %T，%R 和 %D（可能更多）以及早于
   <em>Jan 1, 1970</em> 的时间在 Windows，一些 Linux
   发行版本，以及其它几个操作系统中无效。对于 Windows
   系统，所支持的转换标记可在
   <a href="http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx" class="link external">&raquo;&nbsp;<acronym title="Microsoft Developer Network">MSDN</acronym> 网站</a>找到。
  </p> 
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.strftime-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">format</code></dt>

     <dd>

      <p class="para">
       <table class="doctable table">
        <caption><strong>
         <code class="parameter">format</code> 里能够识别的格式字串有以下标记：</strong></caption>
        
         <thead>
          <tr>
           <th><code class="parameter">格式</code></th>
           <th>描述</th>
           <th>返回值示例</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td style="text-align: center;"><em class="emphasis">日</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%a</em></td>
           <td>当前区域星期几的简写</td>
           <td><em>Sun</em> 到 <em>Sat</em></td>
          </tr>

          <tr>
           <td><em>%A</em></td>
           <td>当前区域星期几的全称</td>
           <td><em>Sunday</em> 到 <em>Saturday</em></td>
          </tr>

          <tr>
           <td><em>%d</em></td>
           <td>月份中的第几天，十进制数字（范围从 01 到 31）</td>
           <td><em>01</em> 到 <em>31</em></td>
          </tr>

          <tr>
           <td><em>%e</em></td>
           <td>
            月份中的第几天，十进制数字，一位的数字前会加上一个空格（范围从 &#039; 1&#039; 到 &#039;31&#039;）
            在 Windows 上尚未按描述实现。更多信息见下方。
           </td>
           <td><em> 1</em> 到 <em>31</em></td>
          </tr>

          <tr>
           <td><em>%j</em></td>
           <td>年份中的第几天，带前导零的三位十进制数（范围从  001 到 366）</td>
           <td><em>001</em> 到 <em>366</em></td>
          </tr>

          <tr>
           <td><em>%u</em></td>
           <td>符合 ISO-8601 星期几的十进制数表达 [1,7]，1 表示星期一</td>
           <td><em>1</em> (星期一) 到 <em>7</em> (星期日)</td>
          </tr>

          <tr>
           <td><em>%w</em></td>
           <td>星期中的第几天，星期天为 0</td>
           <td><em>0</em> (星期天) 到 <em>6</em> (星期六)</td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">周</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%U</em></td>
           <td>本年的第几周，从第一周的第一个星期天作为第一天开始</td>
           <td><em>13</em> (for the 13th full week of the year)</td>
          </tr>

          <tr>
           <td><em>%V</em></td>
           <td>
            %V - 本年第几周的 ISO-8601:1988 格式，范围从 01 到 53，第
            1 周是本年第一个至少还有 4 天的星期，星期一作为每周的第一天。（用
            %G 或者 %g 作为指定时间戳相应周数的年份组成。）
           </td>
           <td><em>01</em> 到 <em>53</em> (where 53
            accounts for an overlapping week)</td>
          </tr>

          <tr>
           <td><em>%W</em></td>
           <td>本年的第几周数，从第一周的第一个星期一作为第一天开始</td>
           <td><em>46</em> (for the 46th week of the year beginning
            with a Monday)</td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">月</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%b</em></td>
           <td>当前区域月份的简写</td>
           <td><em>Jan</em> 到 <em>Dec</em></td>
          </tr>

          <tr>
           <td><em>%B</em></td>
           <td>当前区域月份的全称</td>
           <td><em>January</em> 到 <em>December</em></td>
          </tr>

          <tr>
           <td><em>%h</em></td>
           <td>当前区域月份的简写（%b 的别名）</td>
           <td><em>Jan</em> 到 <em>Dec</em></td>
          </tr>

          <tr>
           <td><em>%m</em></td>
           <td>两位数的月份</td>
           <td><em>01</em> (是一月份) 到 <em>12</em> (是十二月份)</td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">年</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%C</em></td>
           <td>两位数显示世纪（年份除以 100，截成整数）</td>
           <td><em>19</em> 是 20 世纪</td>
          </tr>

          <tr>
           <td><em>%g</em></td>
           <td>
            2 位数的年份，符合 ISO-8601:1988 星期数（参见
            %V）。和 %V 的格式和值一样，只除了如果 ISO 星期数属于前一年或者后一年，则使用那一年。
           </td>
           <td>比如：2009年1月6日那一周是 <em>09</em>。</td>
          </tr>

          <tr>
           <td><em>%G</em></td>
           <td>%g 的完整四位数版本</td>
           <td>比如：2009年1月3日那一周是  <em>2008</em>.</td>
          </tr>

          <tr>
           <td><em>%y</em></td>
           <td>两位数显示年份</td>
           <td>比如： <em>09</em> 是 2009，<em>79</em> 是 1979</td>
          </tr>

          <tr>
           <td><em>%Y</em></td>
           <td>四位数显示年份</td>
           <td>比如： <em>2038</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">时间</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%H</em></td>
           <td>以 24 小时格式显示两位小时数</td>
           <td><em>00</em> 到 <em>23</em></td>
          </tr>

          <tr>
           <td><em>%I</em></td>
           <td>以 12 小时格式显示两位小时数</td>
           <td><em>01</em> 到 <em>12</em></td>
          </tr>

          <tr>
           <td><em>%l（&#039;L&#039; 的小写）</em></td>
           <td>以 12 小时格式显示小时数，单个数字前含空格</td>
           <td><em> 1</em> 到 <em>12</em></td>
          </tr>

          <tr>
           <td><em>%M</em></td>
           <td>两位的分钟数</td>
           <td><em>00</em> 到 <em>59</em></td>
          </tr>

          <tr>
           <td><em>%p</em></td>
           <td>指定时间的大写 “AM” 或 “PM”</td>
           <td>比如： 00:31 是 <em>AM</em> ，22:23 是<em>PM</em></td>
          </tr>

          <tr>
           <td><em>%P</em></td>
           <td>指定时间的小写 “am” 或 “pm”</td>
           <td>比如：00:31 是 <em>am</em> ，22:23 是<em>pm</em></td>
          </tr>

          <tr>
           <td><em>%r</em></td>
           <td>和 &quot;%I:%M:%S %p&quot; 一样</td>
           <td>比如： 21:34:17 是 <em>09:34:17 PM</em></td>
          </tr>

          <tr>
           <td><em>%R</em></td>
           <td>和 &quot;%H:%M&quot; 一样</td>
           <td>比如： 12:35 AM 是 <em>00:35</em>，4:44 PM 是 <em>16:44</em></td>
          </tr>

          <tr>
           <td><em>%S</em></td>
           <td>两位数字表示秒</td>
           <td><em>00</em> 到 <em>59</em></td>
          </tr>

          <tr>
           <td><em>%T</em></td>
           <td>和 &quot;%H:%M:%S&quot; 一样</td>
           <td>比如： 09:34:17 PM 是 <em>21:34:17</em></td>
          </tr>

          <tr>
           <td><em>%X</em></td>
           <td>当前区域首选的时间表示法，不包括日期</td>
           <td>例如： <em>03:59:16</em> 或 <em>15:59:16</em></td>
          </tr>

          <tr>
           <td><em>%z</em></td>
           <td>从 UTC 的时区偏移 或 简写（由操作系统决定）</td>
           <td>比如： 东部时间是 <em>-0500</em> 或 <em>EST</em></td>
          </tr>

          <tr>
           <td><em>%Z</em></td>
           <td>%z 没有给出的 UTC 的时区偏移 或 简写（由操作系统决定）</td>
           <td>比如： <em>-0500</em> 或 <em>EST</em> 是东部时间</td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">时间和日期戳</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%c</em></td>
           <td>当前区域首选的日期时间表达</td>
           <td>比如： 2009 年 2 月 5 日上午 12:45:10 是 <em>Tue Feb  5 00:45:10 2009</em></td>
          </tr>

          <tr>
           <td><em>%D</em></td>
           <td>和 &quot;%m/%d/%y&quot; 一样</td>
           <td>比如： 2009 年 2 月 5 日是 <em>02/05/09</em></td>
          </tr>

          <tr>
           <td><em>%F</em></td>
           <td>Same as &quot;%Y-%m-%d&quot; (commonly used in database datestamps)</td>
           <td>比如：2009 年 2 月 5 日是 <em>2009-02-05</em></td>
          </tr>

          <tr>
           <td><em>%s</em></td>
           <td>Unix纪元的时间戳（和 <span class="function"><a href="time.html" class="function">time()</a></span> 函数一样）</td>
           <td>比如： 1979 年 9 月 10 日上午 8 点 40 分 00 秒是 <em>305815200</em></td>
          </tr>

          <tr>
           <td><em>%x</em></td>
           <td>当前区域首选的时间表示法，不包括时间</td>
           <td>比如： 2009 年 2 月 5 日是 <em>02/05/09</em></td>
          </tr>

          <tr>
           <td style="text-align: center;"><em class="emphasis">其他</em></td>
           <td>---</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%n</em></td>
           <td>换行符(&quot;\n&quot;)</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%t</em></td>
           <td>Tab 字符(&quot;\t&quot;)</td>
           <td>---</td>
          </tr>

          <tr>
           <td><em>%%</em></td>
           <td>文字上的百分字符(&quot;%&quot;)</td>
           <td>---</td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <p class="para">
       这个参数的最大长度是 1023 个字符。
      </p>
      <div class="warning"><strong class="warning">Warning</strong>
       <p class="simpara">
        尽管 ISO 9889:1999（当前的 C 标准）明确指出一周从星期一开始，但是
        Sun Solaris 的一周似乎从星期天开始并作为 1。所以 %u 的结果也许不会和手册里描述得一样。
       </p>
      </div>
      <div class="warning"><strong class="warning">Warning</strong>
       <p class="simpara">
        <em class="emphasis">仅针对 Windows：</em>这个函数里 <em>%e</em> 
        修饰符修饰符还不能支持 Windows。
        为了得到这个值可以用 <em>%#d</em> 修饰符来代替。下例说明了如何写一个跨平台支持的函数。
       </p>
      </div>
      <div class="warning"><strong class="warning">Warning</strong>
       <p class="simpara">
        <em class="emphasis">仅针对 Mac OS X：</em>这个函数里 <em>%P</em> 修饰符还不能支持 Mac OS X。
       </p>
      </div>
     </dd>

    
    
    <dt>
<code class="parameter">timestamp</code></dt>
<dd>
<p class="para">
可选的 <code class="parameter">timestamp</code> 参数是一个 <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> 的 Unix
时间戳，如未指定，参数值默认为当前本地时间。也就是说，其值默认为
<span class="function"><a href="time.html" class="function">time()</a></span> 的返回值。</p></dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.strftime-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   根据指定的 <code class="parameter">timestamp</code> 或未给出 timestamp 是使用当前本地时间，
   返回 <code class="parameter">format</code> 格式化的字符。
   月份、星期名和其他与语言相关的字符串遵守 <span class="function"><a href="setlocale.html" class="function">setlocale()</a></span> 设置的当前区域设置。
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-function.strftime-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
在每 次调用日期/时间函数时，如果时区无效则会引发 <strong><code>E_NOTICE</code></strong> 错误，如果使用系统设定值或 <var class="varname"><var class="varname">TZ</var></var>
环境变量，则会引发 <strong><code>E_STRICT</code></strong> 或 <strong><code>E_WARNING</code></strong> 消息。参见
<span class="function"><a href="date_default_timezone_set.html" class="function">date_default_timezone_set()</a></span>。</p>
  <p class="para">
   由于输出依赖于 C 库，所以一些转换标记并不被支持。
   在 Windows 上，使用未知的转换标记将导致
   5 <strong><code>E_WARNING</code></strong> 信息，并返回 <strong><code>FALSE</code></strong>。
   
   在其他的操作系统上，你可能不能得到任何 <strong><code>E_WARNING</code></strong> 信息，
   并且可能输出未经转换的转换标记。
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.strftime-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      
      <tr><td>5.1.0</td><td><p class="para">
现在发布 <strong><code>E_STRICT</code></strong> 和 <strong><code>E_NOTICE</code></strong>
时区错误。</p></td></tr>

      
     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.strftime-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   如果你的系统里安装了各自的语言环境则下例能够正常运行。
   <div class="example" id="example-2730">
    <p><strong>Example #1 <span class="function"><strong>strftime()</strong></span> 区域的例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_TIME</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"C"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%A"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_TIME</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"fi_FI"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"&nbsp;in&nbsp;Finnish&nbsp;is&nbsp;%A,"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_TIME</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"fr_FR"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"&nbsp;in&nbsp;French&nbsp;%A&nbsp;and"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_TIME</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"de_DE"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"&nbsp;in&nbsp;German&nbsp;%A.\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2731">
    <p><strong>Example #2 ISO 8601:1988 week number example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;December&nbsp;2002&nbsp;/&nbsp;January&nbsp;2003<br />ISOWk&nbsp;&nbsp;M&nbsp;&nbsp;&nbsp;Tu&nbsp;&nbsp;W&nbsp;&nbsp;&nbsp;Thu&nbsp;F&nbsp;&nbsp;&nbsp;Sa&nbsp;&nbsp;Su<br />-----&nbsp;----------------------------<br />51&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16&nbsp;&nbsp;17&nbsp;&nbsp;18&nbsp;&nbsp;19&nbsp;&nbsp;20&nbsp;&nbsp;21&nbsp;&nbsp;22<br />52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;23&nbsp;&nbsp;24&nbsp;&nbsp;25&nbsp;&nbsp;26&nbsp;&nbsp;27&nbsp;&nbsp;28&nbsp;&nbsp;29<br />1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;5<br />2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;10&nbsp;&nbsp;11&nbsp;&nbsp;12<br />3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13&nbsp;&nbsp;14&nbsp;&nbsp;15&nbsp;&nbsp;16&nbsp;&nbsp;17&nbsp;&nbsp;18&nbsp;&nbsp;19&nbsp;&nbsp;&nbsp;*/<br /><br />//&nbsp;输出：&nbsp;12/28/2002&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;52,2002,2002<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"12/28/2002&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"12/28/2002"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;输出：&nbsp;12/30/2002&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;1,2003,2002<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"12/30/2002&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"12/30/2002"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;输出：&nbsp;1/3/2003&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;1,2003,2003<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"1/3/2003&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"1/3/2003"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;输出：&nbsp;1/10/2003&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;2,2003,2003<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"1/10/2003&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"1/10/2003"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /><br /><br /></span><span style="color: #FF8000">/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;December&nbsp;2004&nbsp;/&nbsp;January&nbsp;2005<br />ISOWk&nbsp;&nbsp;M&nbsp;&nbsp;&nbsp;Tu&nbsp;&nbsp;W&nbsp;&nbsp;&nbsp;Thu&nbsp;F&nbsp;&nbsp;&nbsp;Sa&nbsp;&nbsp;Su<br />-----&nbsp;----------------------------<br />51&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;13&nbsp;&nbsp;14&nbsp;&nbsp;15&nbsp;&nbsp;16&nbsp;&nbsp;17&nbsp;&nbsp;18&nbsp;&nbsp;19<br />52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;21&nbsp;&nbsp;22&nbsp;&nbsp;23&nbsp;&nbsp;24&nbsp;&nbsp;25&nbsp;&nbsp;26<br />53&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;27&nbsp;&nbsp;28&nbsp;&nbsp;29&nbsp;&nbsp;30&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;2<br />1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;9<br />2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;11&nbsp;&nbsp;12&nbsp;&nbsp;13&nbsp;&nbsp;14&nbsp;&nbsp;15&nbsp;&nbsp;16&nbsp;&nbsp;&nbsp;*/<br /><br />//&nbsp;输出：&nbsp;12/23/2004&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;52,2004,2004<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"12/23/2004&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"12/23/2004"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;输出：&nbsp;12/31/2004&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;53,2004,2004<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"12/31/2004&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"12/31/2004"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;输出：&nbsp;1/2/2005&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;53,2004,2005<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"1/2/2005&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"1/2/2005"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;输出：&nbsp;1/3/2005&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;1,2005,2005<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"1/3/2005&nbsp;-&nbsp;%V,%G,%Y&nbsp;=&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%V,%G,%Y"</span><span style="color: #007700">,</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"1/3/2005"</span><span style="color: #007700">))&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2732">
    <p><strong>Example #3 <em>%e</em> 修改器跨平台兼容的例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;Jan&nbsp;1:&nbsp;results&nbsp;in:&nbsp;'%e%1%'&nbsp;(%%,&nbsp;e,&nbsp;%%,&nbsp;%e,&nbsp;%%)<br /></span><span style="color: #0000BB">$format&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'%%e%%%e%%'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Check&nbsp;for&nbsp;Windows&nbsp;to&nbsp;find&nbsp;and&nbsp;replace&nbsp;the&nbsp;%e&nbsp;<br />//&nbsp;modifier&nbsp;correctly<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">strtoupper</span><span style="color: #007700">(</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">PHP_OS</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">))&nbsp;==&nbsp;</span><span style="color: #DD0000">'WIN'</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$format&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">preg_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'#(?&lt;!%)((?:%%)*)%e#'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'&lt;/refsect1&gt;%#d'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$format</span><span style="color: #007700">);<br />}<br /><br />echo&nbsp;</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #0000BB">$format</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2733">
    <p><strong>Example #4 显示所有已知和未知的格式</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Describe&nbsp;the&nbsp;formats.<br /></span><span style="color: #0000BB">$strftimeFormats&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'A'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'A&nbsp;full&nbsp;textual&nbsp;representation&nbsp;of&nbsp;the&nbsp;day'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'B'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Full&nbsp;month&nbsp;name,&nbsp;based&nbsp;on&nbsp;the&nbsp;locale'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'C'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two&nbsp;digit&nbsp;representation&nbsp;of&nbsp;the&nbsp;century&nbsp;(year&nbsp;divided&nbsp;by&nbsp;100,&nbsp;truncated&nbsp;to&nbsp;an&nbsp;integer)'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'D'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Same&nbsp;as&nbsp;"%m/%d/%y"'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'E'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'F'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Same&nbsp;as&nbsp;"%Y-%m-%d"'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'G'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'The&nbsp;full&nbsp;four-digit&nbsp;version&nbsp;of&nbsp;%g'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'H'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two&nbsp;digit&nbsp;representation&nbsp;of&nbsp;the&nbsp;hour&nbsp;in&nbsp;24-hour&nbsp;format'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'I'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two&nbsp;digit&nbsp;representation&nbsp;of&nbsp;the&nbsp;hour&nbsp;in&nbsp;12-hour&nbsp;format'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'J'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'K'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'L'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'M'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two&nbsp;digit&nbsp;representation&nbsp;of&nbsp;the&nbsp;minute'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'N'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'O'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'P'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'lower-case&nbsp;"am"&nbsp;or&nbsp;"pm"&nbsp;based&nbsp;on&nbsp;the&nbsp;given&nbsp;time'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'Q'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'R'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Same&nbsp;as&nbsp;"%H:%M"'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'S'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two&nbsp;digit&nbsp;representation&nbsp;of&nbsp;the&nbsp;second'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'T'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Same&nbsp;as&nbsp;"%H:%M:%S"'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'U'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Week&nbsp;number&nbsp;of&nbsp;the&nbsp;given&nbsp;year,&nbsp;starting&nbsp;with&nbsp;the&nbsp;first&nbsp;Sunday&nbsp;as&nbsp;the&nbsp;first&nbsp;week'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'V'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'ISO-8601:1988&nbsp;week&nbsp;number&nbsp;of&nbsp;the&nbsp;given&nbsp;year,&nbsp;starting&nbsp;with&nbsp;the&nbsp;first&nbsp;week&nbsp;of&nbsp;the&nbsp;year&nbsp;with&nbsp;at&nbsp;least&nbsp;4&nbsp;weekdays,&nbsp;with&nbsp;Monday&nbsp;being&nbsp;the&nbsp;start&nbsp;of&nbsp;the&nbsp;week'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'W'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'A&nbsp;numeric&nbsp;representation&nbsp;of&nbsp;the&nbsp;week&nbsp;of&nbsp;the&nbsp;year,&nbsp;starting&nbsp;with&nbsp;the&nbsp;first&nbsp;Monday&nbsp;as&nbsp;the&nbsp;first&nbsp;week'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'X'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Preferred&nbsp;time&nbsp;representation&nbsp;based&nbsp;on&nbsp;locale,&nbsp;without&nbsp;the&nbsp;date'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'Y'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Four&nbsp;digit&nbsp;representation&nbsp;for&nbsp;the&nbsp;year'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'Z'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'The&nbsp;time&nbsp;zone&nbsp;offset/abbreviation&nbsp;option&nbsp;NOT&nbsp;given&nbsp;by&nbsp;%z&nbsp;(depends&nbsp;on&nbsp;operating&nbsp;system)'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'a'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'An&nbsp;abbreviated&nbsp;textual&nbsp;representation&nbsp;of&nbsp;the&nbsp;day'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'b'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Abbreviated&nbsp;month&nbsp;name,&nbsp;based&nbsp;on&nbsp;the&nbsp;locale'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'c'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Preferred&nbsp;date&nbsp;and&nbsp;time&nbsp;stamp&nbsp;based&nbsp;on&nbsp;local'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'d'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two-digit&nbsp;day&nbsp;of&nbsp;the&nbsp;month&nbsp;(with&nbsp;leading&nbsp;zeros)'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'e'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Day&nbsp;of&nbsp;the&nbsp;month,&nbsp;with&nbsp;a&nbsp;space&nbsp;preceding&nbsp;single&nbsp;digits'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'f'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'g'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two&nbsp;digit&nbsp;representation&nbsp;of&nbsp;the&nbsp;year&nbsp;going&nbsp;by&nbsp;ISO-8601:1988&nbsp;standards&nbsp;(see&nbsp;%V)'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'h'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Abbreviated&nbsp;month&nbsp;name,&nbsp;based&nbsp;on&nbsp;the&nbsp;locale&nbsp;(an&nbsp;alias&nbsp;of&nbsp;%b)'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'i'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'j'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Day&nbsp;of&nbsp;the&nbsp;year,&nbsp;3&nbsp;digits&nbsp;with&nbsp;leading&nbsp;zeros'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'k'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'l'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Hour&nbsp;in&nbsp;12-hour&nbsp;format,&nbsp;with&nbsp;a&nbsp;space&nbsp;preceeding&nbsp;single&nbsp;digits'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'m'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two&nbsp;digit&nbsp;representation&nbsp;of&nbsp;the&nbsp;month'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'n'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'A&nbsp;newline&nbsp;character&nbsp;("\n")'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'o'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'p'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'UPPER-CASE&nbsp;"AM"&nbsp;or&nbsp;"PM"&nbsp;based&nbsp;on&nbsp;the&nbsp;given&nbsp;time'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'q'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'r'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Same&nbsp;as&nbsp;"%I:%M:%S&nbsp;%p"'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'s'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Unix&nbsp;Epoch&nbsp;Time&nbsp;timestamp'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'t'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'A&nbsp;Tab&nbsp;character&nbsp;("\t")'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'u'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'ISO-8601&nbsp;numeric&nbsp;representation&nbsp;of&nbsp;the&nbsp;day&nbsp;of&nbsp;the&nbsp;week'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'v'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'w'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Numeric&nbsp;representation&nbsp;of&nbsp;the&nbsp;day&nbsp;of&nbsp;the&nbsp;week'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'x'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Preferred&nbsp;date&nbsp;representation&nbsp;based&nbsp;on&nbsp;locale,&nbsp;without&nbsp;the&nbsp;time'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'y'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Two&nbsp;digit&nbsp;representation&nbsp;of&nbsp;the&nbsp;year'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'z'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'Either&nbsp;the&nbsp;time&nbsp;zone&nbsp;offset&nbsp;from&nbsp;UTC&nbsp;or&nbsp;the&nbsp;abbreviation&nbsp;(depends&nbsp;on&nbsp;operating&nbsp;system)'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'%'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'A&nbsp;literal&nbsp;percentage&nbsp;character&nbsp;("%")'</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #FF8000">//&nbsp;Results.<br /></span><span style="color: #0000BB">$strftimeValues&nbsp;</span><span style="color: #007700">=&nbsp;array();<br /><br /></span><span style="color: #FF8000">//&nbsp;Evaluate&nbsp;the&nbsp;formats&nbsp;whilst&nbsp;suppressing&nbsp;any&nbsp;errors.<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">$strftimeFormats&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$format&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$description</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">False&nbsp;</span><span style="color: #007700">!==&nbsp;(</span><span style="color: #0000BB">$value&nbsp;</span><span style="color: #007700">=&nbsp;@</span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%</span><span style="color: #007700">{</span><span style="color: #0000BB">$format</span><span style="color: #007700">}</span><span style="color: #DD0000">"</span><span style="color: #007700">))){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$strftimeValues</span><span style="color: #007700">[</span><span style="color: #0000BB">$format</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Find&nbsp;the&nbsp;longest&nbsp;value.<br /></span><span style="color: #0000BB">$maxValueLength&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">max</span><span style="color: #007700">(</span><span style="color: #0000BB">array_map</span><span style="color: #007700">(</span><span style="color: #DD0000">'strlen'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$strftimeValues</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;Report&nbsp;known&nbsp;formats.<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">$strftimeValues&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$format&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Known&nbsp;format&nbsp;&nbsp;&nbsp;:&nbsp;'</span><span style="color: #007700">{</span><span style="color: #0000BB">$format</span><span style="color: #007700">}</span><span style="color: #DD0000">'&nbsp;=&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #DD0000">"'</span><span style="color: #007700">{</span><span style="color: #0000BB">$value</span><span style="color: #007700">}</span><span style="color: #DD0000">'"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$maxValueLength</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"&nbsp;(&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$strftimeFormats</span><span style="color: #007700">[</span><span style="color: #0000BB">$format</span><span style="color: #007700">]}</span><span style="color: #DD0000">&nbsp;)\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Report&nbsp;unknown&nbsp;formats.<br /></span><span style="color: #007700">foreach(</span><span style="color: #0000BB">array_diff_key</span><span style="color: #007700">(</span><span style="color: #0000BB">$strftimeFormats</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$strftimeValues</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$format&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$description</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Unknown&nbsp;format&nbsp;:&nbsp;'</span><span style="color: #007700">{</span><span style="color: #0000BB">$format</span><span style="color: #007700">}</span><span style="color: #DD0000">'&nbsp;&nbsp;&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">str_pad</span><span style="color: #007700">(</span><span style="color: #DD0000">'&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$maxValueLength</span><span style="color: #007700">),&nbsp;(</span><span style="color: #0000BB">$description&nbsp;</span><span style="color: #007700">?&nbsp;</span><span style="color: #DD0000">"&nbsp;(&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$description</span><span style="color: #007700">}</span><span style="color: #DD0000">&nbsp;)"&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Known format   : &#039;A&#039; = &#039;Friday&#039;            ( A full textual representation of the day )
Known format   : &#039;B&#039; = &#039;December&#039;          ( Full month name, based on the locale )
Known format   : &#039;H&#039; = &#039;11&#039;                ( Two digit representation of the hour in 24-hour format )
Known format   : &#039;I&#039; = &#039;11&#039;                ( Two digit representation of the hour in 12-hour format )
Known format   : &#039;M&#039; = &#039;24&#039;                ( Two digit representation of the minute )
Known format   : &#039;S&#039; = &#039;44&#039;                ( Two digit representation of the second )
Known format   : &#039;U&#039; = &#039;48&#039;                ( Week number of the given year, starting with the first Sunday as the first week )
Known format   : &#039;W&#039; = &#039;48&#039;                ( A numeric representation of the week of the year, starting with the first Monday as the first week )
Known format   : &#039;X&#039; = &#039;11:24:44&#039;          ( Preferred time representation based on locale, without the date )
Known format   : &#039;Y&#039; = &#039;2010&#039;              ( Four digit representation for the year )
Known format   : &#039;Z&#039; = &#039;GMT Standard Time&#039; ( The time zone offset/abbreviation option NOT given by %z (depends on operating system) )
Known format   : &#039;a&#039; = &#039;Fri&#039;               ( An abbreviated textual representation of the day )
Known format   : &#039;b&#039; = &#039;Dec&#039;               ( Abbreviated month name, based on the locale )
Known format   : &#039;c&#039; = &#039;12/03/10 11:24:44&#039; ( Preferred date and time stamp based on local )
Known format   : &#039;d&#039; = &#039;03&#039;                ( Two-digit day of the month (with leading zeros) )
Known format   : &#039;j&#039; = &#039;337&#039;               ( Day of the year, 3 digits with leading zeros )
Known format   : &#039;m&#039; = &#039;12&#039;                ( Two digit representation of the month )
Known format   : &#039;p&#039; = &#039;AM&#039;                ( UPPER-CASE &quot;AM&quot; or &quot;PM&quot; based on the given time )
Known format   : &#039;w&#039; = &#039;5&#039;                 ( Numeric representation of the day of the week )
Known format   : &#039;x&#039; = &#039;12/03/10&#039;          ( Preferred date representation based on locale, without the time )
Known format   : &#039;y&#039; = &#039;10&#039;                ( Two digit representation of the year )
Known format   : &#039;z&#039; = &#039;GMT Standard Time&#039; ( Either the time zone offset from UTC or the abbreviation (depends on operating system) )
Known format   : &#039;%&#039; = &#039;%&#039;                 ( A literal percentage character (&quot;%&quot;) )
Unknown format : &#039;C&#039;                       ( Two digit representation of the century (year divided by 100, truncated to an integer) )
Unknown format : &#039;D&#039;                       ( Same as &quot;%m/%d/%y&quot; )
Unknown format : &#039;E&#039;
Unknown format : &#039;F&#039;                       ( Same as &quot;%Y-%m-%d&quot; )
Unknown format : &#039;G&#039;                       ( The full four-digit version of %g )
Unknown format : &#039;J&#039;
Unknown format : &#039;K&#039;
Unknown format : &#039;L&#039;
Unknown format : &#039;N&#039;
Unknown format : &#039;O&#039;
Unknown format : &#039;P&#039;                       ( lower-case &quot;am&quot; or &quot;pm&quot; based on the given time )
Unknown format : &#039;Q&#039;
Unknown format : &#039;R&#039;                       ( Same as &quot;%H:%M&quot; )
Unknown format : &#039;T&#039;                       ( Same as &quot;%H:%M:%S&quot; )
Unknown format : &#039;V&#039;                       ( ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week )
Unknown format : &#039;e&#039;                       ( Day of the month, with a space preceding single digits )
Unknown format : &#039;f&#039;
Unknown format : &#039;g&#039;                       ( Two digit representation of the year going by ISO-8601:1988 standards (see %V) )
Unknown format : &#039;h&#039;                       ( Abbreviated month name, based on the locale (an alias of %b) )
Unknown format : &#039;i&#039;
Unknown format : &#039;k&#039;
Unknown format : &#039;l&#039;                       ( Hour in 12-hour format, with a space preceeding single digits )
Unknown format : &#039;n&#039;                       ( A newline character (&quot;\n&quot;) )
Unknown format : &#039;o&#039;
Unknown format : &#039;q&#039;
Unknown format : &#039;r&#039;                       ( Same as &quot;%I:%M:%S %p&quot; )
Unknown format : &#039;s&#039;                       ( Unix Epoch Time timestamp )
Unknown format : &#039;t&#039;                       ( A Tab character (&quot;\t&quot;) )
Unknown format : &#039;u&#039;                       ( ISO-8601 numeric representation of the day of the week )
Unknown format : &#039;v&#039;
</pre></div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 notes" id="refsect1-function.strftime-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    %G 和 %V，如果数字编号系统未能充分理解，基于 ISO 8601:1988
    的星期数可能得出未预期的结果。见上面的 %V 和以下的例子。
   </span>
  </p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.strftime-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="http://strftime.net/" class="link external">&raquo;&nbsp;在线 strftime() 格式设计工具</a></li>
    <li class="member"><span class="function"><a href="setlocale.html" class="function" rel="rdfs-seeAlso">setlocale()</a> - 设置地区信息</span></li>
    <li class="member"><span class="function"><a href="mktime.html" class="function" rel="rdfs-seeAlso">mktime()</a> - 取得一个日期的 Unix 时间戳</span></li>
    <li class="member"><span class="function"><a href="strptime.html" class="function" rel="rdfs-seeAlso">strptime()</a> - 解析由 strftime 生成的日期／时间</span></li>
    <li class="member"><span class="function"><a href="gmstrftime.html" class="function" rel="rdfs-seeAlso">gmstrftime()</a> - 根据区域设置格式化 GMT/UTC 时间／日期</span></li>
    <li class="member"><a href="http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html" class="link external">&raquo;&nbsp;Open Group specification of <span class="function"><strong>strftime()</strong></span></a></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>